@extends('admin.pub.pub')
@section('title','课程列表')
@section('bread1','视频课程管理')
@section('bread2','课程列表')
@section('css')
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap-theme.min.css" rel="stylesheet">
@endsection
@section('content')
    <div class="container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l">
				<a class="btn btn-primary radius" data-title="添加课程" data-href="{{ route('admin.course.create') }}"
                   onclick="Hui_admin_tab(this)" href="javascript:;">
					<i class="Hui-iconfont">&#xe600;</i> 添加课程
				</a>
			</span>
        </div>
        <table class="table table-hover">
            <thead>
            <tr>
                <th>ID</th>
                <th>课程名称</th>
                <th>讲师</th>
                <th>分类</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @forelse($data as $item)
                <tr>
                    <td>{{ $item->id }}</td>
                    <td>{{ $item->name }}</td>
                    <td>{{ $item->teacher }}</td>
                    <td>{{ $item->category->name }}</td>
                    <td>
                        <a href="javascript:;" onclick="role_edit('[{{ $item->name }}] - 修改','{{ route('admin.course.edit',['course'=>$item->id]) }}')" class="btn btn-success-outline">修改</a>
                        <a href="javascript:;" onclick="role_del('{{ route('admin.course.destroy',['course'=>$item->id]) }}')" class="btn btn-danger-outline">删除</a>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="3">暂无数据</td>
                </tr>
            @endforelse
            </tbody>
        </table>
        <div>
            {{ $data->links() }}
        </div>
    </div>
@endsection
@section('js')
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/js/bootstrap.min.js"></script>
    <script>
        // 编辑
        function role_edit(title,url){
	        layer.open({
		        type: 2,
		        title: title,
		        content: url,
		        area:['750px','500px']
	        });
        }

        // 删除
        function role_del(url) {
        	var _token = '{{ csrf_token() }}';
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    url,
                    type: 'DELETE',
                    data: {_token},
                    dataType: 'json',
                    success(res) {
                        if (res.status == 0) {
                            layer.msg('删除成功',{time:1000},function () {
                                location.replace(location.href);
                            });
                        } else {
                            layer.alert('删除失败')
                        }
                    }
                })
            });
        }
    </script>
@endsection